package com.ls.pattern.adapter.v2;

import com.ls.pattern.adapter.ResultMsg;
import com.ls.pattern.adapter.v2.adapters.ILoginAdapter;
import com.ls.pattern.adapter.v2.adapters.LoginForQQAdapter;
import com.ls.pattern.adapter.v2.adapters.LoginForWeChatAdapter;

/**
 * 三方登录适配器
 *
 * @author 挥之以墨
 */
public class PassportThirdAdapter implements IPassportThird {

    @Override
    public ResultMsg loginForqq(String openid) {
        return processLogin(openid, LoginForQQAdapter.class);
    }

    @Override
    public ResultMsg loginForWeChat(String openid) {
        return processLogin(openid, LoginForWeChatAdapter.class);
    }

    private ResultMsg processLogin(String id, Class<? extends ILoginAdapter> clazz) {
        try {
            ILoginAdapter adapter = clazz.newInstance();
            return adapter.login(id, adapter);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
